package cn.demo.app.fallback;

import cn.demo.app.a.domain.User;
import cn.demo.app.api.EchoApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: float 2022/11/3 09:56
 */
@Lazy
@Component
public class EchoFallBackFactory implements FallbackFactory<EchoApi> {

    public final Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public EchoApi create(Throwable cause) {
        log.error(cause.toString());
        log.error("echoFallBackFactory:", cause);
        return new EchoApi() {
            @Override
            public void echo(String msg) {
                System.out.println("fallBack logic");
            }

            @Override
            public List<User> list(User user) {
                System.out.println("fallBack list logic");
                return null;
            }

            @Override
            public ResponseEntity<byte[]> download() {
                return null;
            }
        };
    }

    // FeignException$ServiceUnavailable
    // FeignException$InternalServerError
}
